<!DOCTYPE html>
<head>
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
  <title>Coverage for {{gitiles_commit.project}}</title>
  <meta charset="utf-8">
  <link rel="stylesheet" href="/common.css">
  <style>
    .coverage-header {
      padding: 5px 10px;
      border-bottom: 1px solid #DBDBDB;
      background-color: #EEE;
      line-height: 24px;
      text-align: center;
      font-weight: bold;
      font-size: 18px;
    }
    .intro-text {
      box-sizing: border-box;
      width: 100%;
      padding: 0.5em 8px;
      margin: 0.5em auto;
      border: 1px solid #ccc;
      background: #f8f8f8;
      font-size: 14px;
    }
    .disabled-link {
      color: darkgray;
    }
  </style>
  <script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
  <link rel="import" href="/ui/elements/cats-app.html">
  <link rel="import" href="/ui/elements/coverage/coverage-documentation.html">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="/ui/js/coverage.js"></script>
  <script>
    $(function() {
      document.getElementById('app').userInfo = {{ (user_info or {}) | tojson | safe }};
      document.getElementById('app').banner = {{ (banner or {}) | tojson | safe }};
    });
  </script>
</head>

<body>
  <cats-app id="app" components="Infra>Test>CodeCoverage" page-header="Code Coverage: summary by revisions (Chrome Browser for {{platform_ui_name}})">
    <coverage-documentation></coverage-documentation>
    <br>
    <div class="intro-text">
    <p>These reports give test code coverage for {{gitiles_commit.project}} project.</p>
    <p>Currently showing the code coverage on the {{gitiles_commit.ref}} branch.</p>
    </div>
        <form id="platform_select_form" method="get">
          Platform:
          <select id="platform_select" name="platform" onchange="switchPlatform()">
          {% for option in platform_select.options %}
            <option value="{{option.value}}" {% if option.selected %}selected="selected" {% endif %}>{{option.ui_name}}</option>
          {% endfor %}
          <input type="hidden" name="list_reports" value="true"></input>
          </select>
        </form>
      <table>
        <thead>
          <tr class="coverage-header">
            {% if user_info and user_info.is_admin %}
              <th colspan="8">{{gitiles_commit.project}}</th>
            {% else %}
              <th colspan="7">{{gitiles_commit.project}}</th>
            {% endif %}
          </tr>
          <tr>
            <th title="Link to code coverage report for the particular commit position.">Report</th>
            <th title="Time when the revision was commited into the source tree.">Commit Time (PST)</th>
            <th title="Commit used to build targets and generate code coverage report.">Commit</th>
            {% for m in metrics %}
              <th title="{{ m.detail }}">{{ m.name | capitalize }} </th>
            {% endfor %}
            <th title="Link to the build that generated this report.">Data Source</th>
            {% if user_info and user_info.is_admin %}
              <th>Is Visible</th>
            {% endif %}
          </tr>
        </thead>

        <tbody>
        {% for datum in data %}
          {% if user_info and user_info.is_admin or datum.visible %}
            <tr>
              <td>
                <a href="/p/chromium/coverage/dir?host={{datum.gitiles_commit.server_host}}&project={{datum.gitiles_commit.project}}&ref={{datum.gitiles_commit.ref}}&revision={{datum.gitiles_commit.revision}}&path=//&platform={{platform}}">Link</a>
              </td>
              <td>
                {{datum.commit_timestamp}}
              </td>
              <td>
                <a href="https://{{datum.gitiles_commit.server_host}}/{{datum.gitiles_commit.project}}/+/{{datum.gitiles_commit.revision}}">{{datum.gitiles_commit.revision[:7]}}</a>
              </td>
              {% for target_metric in metrics %}
                {% set found = False %}
                <td>
                {% for metric in datum.summary_metrics %}
                  {% if not found and metric.name == target_metric.name %}
                    {% set found = True %}
                    {% if metric.total == 0 %}
                      {% set percent = 100 %}
                    {% else %}
                      {% set percent = (metric.covered*100.0/metric.total) | int %}
                    {% endif %}
                    {{ ('%3d' % percent).replace(' ', '&nbsp;') | safe }}%
                    ({{ metric.covered }}/{{ metric.total }})
                  {% endif %}
                {% endfor %}
                </td>
              {% endfor %}
              <td>
                <a href="https://ci.chromium.org/b/{{datum.build_id}}">Build</a>
              </td>
              {% if user_info and user_info.is_admin %}
                <td>{{datum.visible}}</td>
              {% endif %}
            </tr>
          {% endif %}
        {% endfor %}
        </tbody>
      </table>
      {% if prev_cursor != '' %}
        <a href="/p/{{luci_project}}/coverage/dir?host={{gitiles_commit.host}}&project={{gitiles_commit.project}}&ref={{gitiles_commit.ref}}&platform={{platform}}&list_reports=true&direction=previous&cursor={{prev_cursor}}">Previous</a>
      {% else %}
        <span class="disabled-link">Previous</span>
      {% endif %}
      {% if next_cursor != '' %}
        <a href="/p/{{luci_project}}/coverage/dir?host={{gitiles_commit.host}}&project={{gitiles_commit.project}}&ref={{gitiles_commit.ref}}&platform={{platform}}&list_reports=true&direction=next&cursor={{next_cursor}}">Next</a>
      {% else %}
        <span class="disabled-link">Next</span>
      {% endif %}
    </div>
  </cats-app>
</body>
